
	
	function _msglist_show()
	{
		//alert("hahah");
		var msgid=$(this).attr("id");
		console.log(typeof(msgid)+":"+msgid);
		var fid="f"+msgid.replace("msg","");
		console.log(fid);
		$(".li").remove("#"+msgid);
		console.log($("#msglist").has(".li"));
		if($("#msglist").has(".li").length<=0)
		{
			$("#msgbox").css("display","none");
		}
		$("#"+fid).trigger("click",[fid]);
		
	}



	//-------------------------------发送消息方法----------------------------------------------------------------------------------------------------------------------------
	function sendword(cid,v)
	{	
		//var cid=cid;
		var towho=cid.replace("c","");

		if($.trim(v)=="")
		{
			return false;
		}
		
		//ajax提交
		var sendsay={
			url:'sayComet.php',
			type:'POST',
			data:'u='+gbl.user+'&&content='+v+'&&to='+towho,
			success:function(msg)
			{
				console.log(msg);
				if(msg=='ok')
				{
					
					$("#"+cid+" > .chat_box").html($("#"+cid+" > .chat_box").html()+"<div class='demo clearfix fr'><div class='article'>"+v+"</div></div>");
					$("#"+cid+" > .input").val("");
				}
				else
				{
					alert('错了'+msg);
				}
				$("#"+cid+" > .chat_box")[0].scrollTop = $("#"+cid+" > .chat_box")[0].scrollHeight;
			}
		};
		$.ajax(sendsay);			
	}


	//--------------------------------------轮询消息-------------------------------------------------------------------------------------------------------------------------------
		var sendchunk={
			type:'GET',
			data:'u='+gbl.user,
			dataType:'json',
			url:'requestComet.php',
			success:function(msg)
			{
				if(msg.w!=0)
				{
					makewrite(msg.w);
				}
				if(msg.m!=0)
				{
					console.log("msg="+msg);
					console.log("msg.m="+msg.m);
					makemsgbox(msg.m);
					//这里添加提示音
				}
				/*if(msg.af!=0)
				{
					makemsgbox(msg.af);
				}*/

				window.setTimeout(function(){$.ajax(sendchunk);},1000);
			}
		};
		//$.ajax(sendchunk);


		function makemsgbox(msg)
		{
			if(msg==0)
			{
				return;
			}
			console.log("轮询收到:"+msg);
			var fromid=msg.fromid;
			var cid="c"+fromid;
			var fid="f"+fromid;

			//console.log($("#"+cid).find(".chat_box"));
			console.log("fromid:"+fromid+"  cid:"+cid+"  fid:"+fid+"  taid:"+gbl.talkingid);
			console.log("来自:frdid:"+fromid+":"+msg.content);

			//如果该联系人面板尚未创建
			if(!$(".ischat").is("#"+fid))
			{
				//如果消息不是当前聊天的联系人的话	
				if(parseInt(fromid)!=parseInt(gbl.talkingid))
				{
					console.log(parts.msgbox);
					parts.msgbox.add(msg);
				}
			}
			else
			{
				console.log("--------添加聊天信息------");
				//接受信息后去除正在输入文字
				var str=$("#"+cid).find(".chat_box").html();
				console.log("----"+str.indexOf("正在输入"));
				if(str.indexOf("正在输入")>=0)
				{
					str=str.replace("\t\t正在输入...","");
					$("#"+cid).find(".chat_top").html(str);
				}
					
				//增加信息
				var h=$("#"+cid).find(".chat_box").html();
				$("#"+cid).find(".chat_box").html(h+"<div class='demo clearfix'><div class='article'>"+msg.content+"</div></div>");
				
				

				$("#"+cid).find(".chat_box")[0].scrollTop = $("#"+cid).find(".chat_box")[0].scrollHeight;

				
			}
		}

		function makewrite(who)
		{
			console.log(who);
			 var id =who;
			 tempvar.currentid=id;
				 

			 if($(".page").is("#c"+id))
			 {
				 //如果还没有有正在输入字眼，则添加正在输入文字
				 console.log($("#c"+id+" > .chat_top").html().indexOf("正在输入"));
				 if($("#c"+id+" > .chat_top").html().indexOf("正在输入")<0)
				 {
					 console.log("in if");
					 $("#c"+id+" > .chat_top").html($("#c"+id+" > .chat_top").html()+"\t\t正在输入...");
					  console.log($("#c"+id+" > .chat_top").html());
				 }
					
			 }
		}
		function makefrdmsg(msg)
		{
			
		}

//-----------------------------------------获取好友状态--------------------------------------------------------------------------------------------------------------
var getstatus={
		url:'status.php',
		type:'POST',
		data:'u='+gbl.user+"&&m=all",
		dataType:'json',
		success:function(usts)
		{
			//console.log(usts);
			//console.log(usts[0].status);
			//console.log(usts.0);
			for(var i=0;i<usts.length;i++)
			{
				var fid="f"+usts[i].frdid;
				if($(".fds").is("#"+fid))
				{	
					if(usts[i].status==0)
					{
						$("#"+fid).find(".imagehead").html("离线");
					}
					else if(usts[i].status==1)
					{
						$("#"+fid).find(".imagehead").html("在线");


					}
					else if(usts[i].status==2)
					{
						$("#"+fid).find(".imagehead").html("离开");

					}
					else if(usts[i].status==3)
					{
						$("#"+fid).find(".imagehead").html("勿扰");

					}
				}
			}
			
			window.setTimeout(function(){$.ajax(getstatus);},25000);
		}

	};
	//$.ajax(getstatus);

/*
---------------------------获取好友输入状态--------------------------------------------------------------------------------------------------------
*/

/* var getWrite={
	  url:'getsaying.php',
	  data:"u="+gbl.user,
	  type:'GET',
	  success:function(who)
	  {
		  
		 console.log(who);
		 var id =who;
		 tempvar.currentid=id;
			 

		 if($(".page").is("#c"+id))
		 {
			 //如果还没有有正在输入字眼，则添加正在输入文字
			 console.log($("#c"+id+" > .chat_top").html().indexOf("正在输入"));
			 if($("#c"+id+" > .chat_top").html().indexOf("正在输入")<0)
			 {
				 console.log("in if");
				 $("#c"+id+" > .chat_top").html($("#c"+id+" > .chat_top").html()+"\t\t正在输入...");
				  console.log($("#c"+id+" > .chat_top").html());
			 }
				
		 }
		
		window.setTimeout(function(){$.ajax(getWrite);},1000);
	  }
  };

//开启轮询查看好友输入状态
$.ajax(getWrite);
*/

//每隔3秒清除正在输入文字
	window.setInterval(function(){
		if(tempvar.currentid>0)
		{
			console.log("in no currentid:"+tempvar.currentid);
			if($(".page").is("#c"+tempvar.currentid))
			{
				var str=$("#c"+tempvar.currentid+" > .chat_top").html();
				console.log("str"+str);
				if(str.indexOf("正在输入"))
				{
					str=str.replace("\t\t正在输入...","");
					$("#c"+tempvar.currentid+" > .chat_top").html(str);
				}
			}
			tempvar.currentid=0;
		}
		
	},3000);

